package com.chinasoft.mall.activity.adapter;

import java.util.List;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.chinasoft.mall.R;
import com.chinasoft.mall.activity.MainActivity;
import com.chinasoft.mall.activity.subActivity.search.SearchListActivity;
import com.chinasoft.mall.framework.Config;
import com.chinasoft.mall.model.BaseBean;

public class SearchAdapter extends BaseAdapter {
	private List<String> dds;
	private LayoutInflater inflater;
	private MainActivity MainActivity;
	private ViewHolder _vh;

	public SearchAdapter(MainActivity MainActivity, List<String> crs) {
		inflater = LayoutInflater.from(MainActivity);
		this.MainActivity=MainActivity;
		this.dds = crs;
	}
	
	public void setData(List<String> crs){
		this.dds=crs;
		this.notifyDataSetChanged();
	}
	
	@Override
	public int getCount() {
		if (dds == null) {
			return 0;
		} else {
			return dds.size();
		}
	}

	@Override
	public Object getItem(int position) {
		if (dds == null) {
			return null;
		} else {
			return dds.get(position);
		}
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.search_lv, null);
			_vh = new ViewHolder();
			_vh.hotwords=(TextView) convertView.findViewById(R.id.hotwords);
			convertView.setTag(_vh);
		} else {
			_vh = (ViewHolder) convertView.getTag();
		}
		String _dd=dds.get(position);
		_vh.hotwords.setText(_dd);
		convertView.setOnClickListener(new onClickImpl(MainActivity,_dd));
		return convertView;
	}
	
	/**
	 * 跳转到通道详情
	 * 
	 * @author Administrator
	 * 
	 */
	class onClickImpl implements View.OnClickListener {
		private String scd;
		private MainActivity MainActivity;

		public onClickImpl(MainActivity MainActivity, String scd) {
			this.scd = scd;
			this.MainActivity = MainActivity;
		}

		@Override
		public void onClick(View v) {
			if (scd != null) {
			BaseBean searchgoods=new BaseBean(Config.SEACH_GOODS);
			searchgoods.reqData.put("goods_name", scd);
				MainActivity.setCurrentActivity(SearchListActivity.class, scd, searchgoods);
			}
		}
	}

	class ViewHolder {
		public TextView hotwords;
	}
}
